/*
 * Copyright 2012 Alain Pannetrat (L1L1@gmx.com)
 * 
 * This file is part of cookie-miner.
 * 
 * cookie-miner is free software: you can redistribute it and/or modify 
 * it under the terms of the GNU General Public License as published by 
 * the Free Software Foundation, either version 3 of the License, or 
 * (at your option) any later version.
 * 
 * cookie-miner is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License 
 * along with cookie-miner. If not, see http://www.gnu.org/licenses/.
 *
 * @version: $Id$
 *
 */
#ifndef _GFX_ENGINE_GTK_H_
#define _GFX_ENGINE_GTK_H_

#include <string>

#include <SDL.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <FTGL/ftgl.h>
#include "common.h"
#include "gfx_widgets.h"


namespace gfx {

	class Font {
		public:
			Font() : _font(NULL) {}
			bool load(const char *name, unsigned size);
			bool loaded() { return _font!=NULL; }

			bool extent(double& width, double &height, const char *txt, int len=-1);
			bool extent(double& width, double &height, const std::string& txt) {
				return extent(width,height,txt.data(),txt.size()); }
			
			bool render_text(double x, double y, const char *txt, int len=-1);
			bool render_text(double x, double y, const std::string& txt) {
				return render_text(x,y,txt.data(),txt.size()); }

			void unload();	
			~Font();
		private:
			FTTextureFont* _font;

			DISALLOW_COPY_AND_ASSIGN(Font);
	};

	class Texture {
		public:
			Texture() : _image(NULL), _binded(false) {}
			bool binded() const { return _binded; }
			bool load(const char *fname);
			bool bind();
			unsigned value() const { return _texture; }
			void blit(double x1, double y1, double x2, double y2); 
			~Texture();
		private:
			SDL_Surface *_image;
			unsigned _texture;
			bool _binded;
	};

	class Engine {
		public:
			static Font SansSerifFont;
			static Texture RoundPoint;

			Engine();

			virtual bool idle();

			static unsigned time();		
			
			bool init(Widget* main_widget);

			bool screen_setup(bool do_fullscreen, int height=0, int width=0);
			
			bool run();

			Widget* main_widget();

			bool fullscreen() const { return _fullscreen; }

			int screen_width() const { return _surface->w; }

			int screen_height() const { return _surface->h; }

			virtual ~Engine();
		private:
			Widget* _main_widget;
			unsigned _last_time;
			unsigned _last_click;
			SDL_Surface *_surface;
			bool _fullscreen;

			//static unsigned _big_bang;
			static bool _init_engine_core;
			static int _desktop_width;
			static int _desktop_height;

			DISALLOW_COPY_AND_ASSIGN(Engine);
	}; 
}


#endif
